package hms.employees;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import hms.database.DBRowObject;

/**
 * JobTitle contains a person's job title, and methods to communicate to the
 * database.
 * 
 * @author Ben
 * 
 */
public class JobTitle extends DBRowObject {
	
	// Fields from the DB that you want to manipulate in Java
	
	private String jobTitle;
	
	// Add 2 constructors - a no-arg default and one that takes a UniqueID as an int
	
	public JobTitle() {
		super();
		jobTitle = "Undefined";
	}
	
	public JobTitle(int uniqueID) {
		super(uniqueID);
	}
	
	// Add more constructors, if you wish, to make creating new objects easier
	
	public JobTitle(String jobTitle) {
		super();
		this.jobTitle = jobTitle;
		markAsChanged();
	}
	
	// Getters and setters.  Be sure setters save database-safe data and call
	// markAsChanged().
	
	public String getJobTitle() {
		return jobTitle;
	}
	
	public void setJobTitle(String newTitle) {
		jobTitle = reduceCharset(newTitle);
		markAsChanged();
	}
	
	public String toString() {
		return getJobTitle();
	}

	// Super's abstract methods, which you must override to define the behavior
	// between your object and the database.
	//
	// READ THE JAVADOCS (mouse over the function names!) to see how to fill
	// out each one.  There is example code for everything.
	
	@Override
	protected String[] getFieldNames() {
		String[] fn = new String[1];
		fn[0] = "JOBTITLE";
		return fn;
	}

	@Override
	protected void loadPreparedStatement(PreparedStatement stmt)
			throws SQLException {
		stmt.setString(1, jobTitle);
		
	}

	@Override
	protected String getUniqueIdentifierFieldName() {
		return "JOBTITLE_ID";
	}

	@Override
	protected String getTableName() {
		return "JOBTITLE";
	}

	@Override
	protected void loadFromDatabase(ResultSet rs) throws SQLException {
		this.jobTitle = rs.getString("JOBTITLE");
	}

	@Override
	protected boolean allowDuplicateRows() {
		// TODO Auto-generated method stub
		return false;
	}

}
